<template>
    <div>
        <el-form :model="customerForm" :rules="rules" ref="customerForm" label-width="120px" size="small"
                 style="width: 30%; margin: 40px 10px 15px 50px">
            <el-form-item prop="orderUser" label="客户">
                <el-select ref="customer" v-model="customerForm.customerName" filterable @change="initCustomer">
                    <el-option v-for="item in customerData" :key="item.customerId" :label="item.customerName"
                               :value="item"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item v-show="false" prop="orderUser" label="客户Id">
                <el-input v-model="customerForm.customerId" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item prop="orderUserPhone" label="客户电话">
                <el-input v-model="customerForm.phone" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item prop="payMethod" label="记账方式">
                <el-select v-model="customerForm.payMethod" clearable>
                    <el-option v-for="item in this.GLOBAL.payMethod" :key="item.value" :label="item.label"
                               :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="payStatus" label="付款状态">
                <el-select v-model="customerForm.payStatus" clearable>
                    <el-option v-for="item in this.GLOBAL.payStatus" :key="item.value" :label="item.label"
                               :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
    export default {
        name: 'OrderStep1',
        data() {
            return {
                customerData: [],
                customerForm: {
                    customerId: '',
                    customerName: '',
                    phone: '',
                    payMethod: '',
                    payStatus: ''
                },
                rules: {
                    // orderUser: [
                    //     {required: true, message: '请选择客户', trigger: 'change'}
                    // ],
                    payMethod: [
                        {required: true, message: '请选择记账方式', trigger: 'change'}
                    ],
                    payStatus: [
                        {required: true, message: '请选择付款状态', trigger: 'change'}
                    ]
                }

            }
        },
        props: ['active'],
        created() {
            this.queryCustomer()
        },
        methods: {
            initCustomer(value) {
                // console.log(value)
                this.customerForm.customerId = value.customerId
                this.customerForm.phone = value.customerPhone
            },
            queryCustomer() {
                this.request.get("/customer/findAll").then(res => {
                    this.customerData = res.data
                })
            },
            checkValidate() {
                let flag = false
                this.$refs['customerForm'].validate((valid) => {
                    if (valid) {
                        flag = true
                    }
                })
                return flag
            }
        }
    }
</script>
<style>
    .TKform {
        width: 100%;
        padding: 20px 50px;
    }
</style>